// pages/component/homes/purchase/clubrecord/clubrecord.js
var that;
var dataManager = require('../../../../../utils/dataManager.js');
var GlobalData = require('../../../../../utils/GlobalData.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cardRecordArr: [],
    page: 20,
    arrlength: 0,
    haveData: false,
    hidden: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    dataManager.removeBtnObserver("clubrecord")
    this.setData({
      hidden: true
    })
    if (GlobalData.ClubRechargeRecord) {
      this.onComplete();
    } else {
      dataManager.rigisterObserver("clubrechargerecord", this.onComplete, this);
      dataManager.getClubRechargeRecord(GlobalData.RechargeRecordother["index"], GlobalData.RechargeRecordother["size"], GlobalData.RechargeRecordother["add"]);
    }
  },
  onComplete: function () {
    if (GlobalData.ClubRechargeRecord.length == this.data.arrlength)
      return;
    var dataTemp = GlobalData.ClubRechargeRecord;
    for (let i = 0; i < dataTemp.length; i++) {
      let index = dataTemp[i].createtime.indexOf('T');
      dataTemp[i]["date"] = dataTemp[i].createtime.substring(0, index);
      dataTemp[i]["time"] = dataTemp[i].createtime.substring(index, dataTemp[i].createtime.length);
      dataTemp[i]["time"] = dataTemp[i]["time"].replace('T', '');
    }

    this.setData({
      cardRecordArr: dataTemp,
      arrlength: this.data.cardRecordArr.length
    })

    /**判断是否有数据 */
    if (dataTemp.length)
      this.setData({
        haveData: true
      })
  },
  goBuyCardDetail: function (e) {
    var card = e.currentTarget.dataset.id;
    // console.log(e, card)
    GlobalData.sysno = card.sysno;
    this.setData({
      hidden: false
    })
    dataManager.OnRequestPost({ method: "getorderdetail", "token": GlobalData.token, "sysno": card.sysno }, this.onCompletDetail, false, this.onError)
  },
  onError: function () {
    this.setData({
      hidden: true
    })
  },
  onCompletDetail: function (data) {
    GlobalData.clubOrderdetail = GlobalData.clone(data)

    // if (dataManager.isClick("clubdetail")) {
    //   return
    // } else {
    //   dataManager.btnObserver("clubdetail")
    this.setData({
      hidden: true
    })
    dataManager.UseNavigateTo('../../purchase/clubdetail/clubdetail', false);
    // }

  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    // console.log("页面上拉触底事件的处理函数");
    GlobalData.RechargeRecordother["index"] = GlobalData.RechargeRecordother["index"] + 1;
    dataManager.rigisterObserver("EarningDetail", this.onComplete, this);
    dataManager.getClubRechargeRecord(GlobalData.RechargeRecordother["index"], GlobalData.RechargeRecordother["size"], true);

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})